const AcGameObjects = [];

export class AcGameObject {
  constructor() {
    AcGameObjects.push(this);
    this.timedelta = 0;
    this.has_start = false;
  }

  start() {}

  update() {}

  on_destory() {
    //删除之前执行
  }

  destory() {
    for (let i in AcGameObjects) {
      const obj = AcGameObjects[i];
      if (obj === this) {
        AcGameObjects.splice(i);
        break;
      }
    }
  }
}
let lastTimestamp;
const step = (timestamp) => {
  for (let obj of AcGameObjects) {
    if (!obj.has_start) {
      obj.has_start = true;
      obj.start();
    } else {
      obj.timedelta = timestamp - lastTimestamp;

      obj.update();
    }
  }
  lastTimestamp = timestamp;
  requestAnimationFrame(step);
};

requestAnimationFrame(step);
